home *** CD-ROM | disk | FTP | other *** search
-
- NAME
- gdbm - GNU database routines
-
- SYNOPSIS
- #include <gdbm.h>
-
- GDBM_FILE gdbm_open(name, block_size, read_write, mode, fatal_func)
- char *name;
- int block_size;
- int read_write;
- int mode;
- void (*fatal_func)();
-
- void gdbm_close(dbf)
- GDBM_FILE dbf;
-
- int gdbm_store(dbf, key, content, flags)
- GDBM_FILE dbf;
- datum key;
- datum content;
- int flags;
-
- datum gdbm_fetch(dbf, key)
- GDBM_FILE dbf;
- datum key;
-
- int gdbm_delete(dbf, key)
- GDBM_FILE dbf;
- datum key;
-
- datum gdbm_firstkey(dbf)
- GDBM_FILE dbf;
-
- datum gdbm_nextkey(dbf, key)
- GDBM_FILE dbf;
- datum key;
-
- int gdbm_reorganize(dbf)
- GDBM_FILE dbf;
-
- DESCRIPTION
- This is release 1.5 of GNU dbm. Also included is support for
- standard UNIX dbm(3x) and ndbm(3). For information on these,
- see the corresponding documentation.
-
- GNU dbm is a set of database routines that use extendible hash-
- ing and works similar to the standard UNIX dbm routines. The
- basic unit of data is the structure:
-
- typedef struct {
- char *dptr;
- int dsize;
- } datum;
-
- An include file will be produced that can be included by the
- user. The file is ``gdbm.h''. ``dbm.h'' and ``ndbm.h'' are also
- provided if they are not already available.
-
- GNU dbm allows multiple data files. A routine that opens a gdbm
- file is designated as a "reader" or a "writer". Only one writer
- may open a gdbm file and many readers may open the file.
- Readers and writers can not open the gdbm file at the same
- time. The procedure for opening a gdbm file is:
-
- GDBM_FILE dbf;
-
- dbf = gdbm_open(name,block_size,read_write,mode,fatal_func)
-
- The parameters are:
-
- char *name
- the name of the file (the complete name, gdbm does not
- append any characters to this name)
-
- int block_size
- the size of a single transfer from disk to memory. This
- parameter is ignored unless the file is a new file. The
- minimum size is 512. If it is less than 512, dbm will
- use the stat block size for the file system.
-
- int read_write
- 0 => reader, 1 => writer, 2 => writer (if the database
- does not exist, create a new one, 3 => writer and create
- a new database regardless if one exists. (Defined in
- gdbm.h as GDBM_READER, GDBM_WRITER, GDBM_WRCREAT,
- GDBM_NEWDB.)
-
- int mode
- file mode (see chmod(2) and open(2)) if the file is
- created.
-
- void (*fatal_func)()
- a function for dbm to call if it detects a fatal error.
- The only parameter of this function is a string. If the
- value of 0 is provided, gdbm will use a default
- function.
-
- The return value, dbf, is the pointer needed by all other
- routines to access that gdbm file. If the return is the NULL
- pointer, gdbm_open was not successful. The errors can be found
- in "gdbm_errno" for gdbm errors and in "errno" for file system
- errors. (For error codes, see gdbmerrno.h.)
-
- In all of the following calls, the parameter "dbf" refers to the
- pointer returned from gdbm_open.
-
- It is important that every file opened is also closed. This is
- needed to update the reader/writer count on the file. This is
- done by:
-
- gdbm_close(dbf);
-
- The database is used by 3 primary routines. The first stores
- data in the database.
-
- ret = gdbm_store(dbf, key, content, flag)
-
- The parameters are:
-
- GDBM_FILE dbf
- the pointer returned by gdbm_open
-
- datum key
- the key data
-
- datum content
- the data to be associated with the key
-
- int flag
- 0 => insert only, generate an error if key exists. 1 =>
- replace contents if key exists. (Defined in gdbm.h as
- GDBM_INSERT and GDBM_REPLACE.)
-
- If a reader calls store, ret gets -1. If called with
- GDBM_INSERT and key is in the database, ret gets 1.
- Otherwise, ret is 0. NOTICE: If you store data for a
- key that is already in the data base, gdbm replaces the
- old data with the new data if called with GDBM_REPLACE.
- You do not get two data items for the same key and you
- do not get an error from gdbm_store. NOTICE: The size
- in gdbm is not restricted like dbm or ndbm. Your data
- can be as large as your "want". NOTICE: Both key and
- content must have the dptr field be a non-NULL value.
- Since a NULL dptr field is used by other routines to
- indicate an error, a NULL field cannot be valid data.
- If either key or content have a null dptr field,
- gdbm_open will return an error.
-
- To search for some data:
-
- content = gdbm_fetch(dbf, key)
-
- The parameters are:
-
- GDBM_FILE dbf
- the pointer returned by gdbm_open
-
- datum key
- the key data
-
- The "datum" returned in content is a pointer to the data
- found. If the dptr is NULL, no data was found. If dptr
- is not NULL, then it points to data allocated by
- malloc. gdbm does not automatically free this data.
- The user must free this storage when done using it.
- This eliminates the need to copy the result to save it
- for later use. (You just save the pointer.)
-
- To remove some data from the database:
-
- ret = gdbm_delete(dbf, key)
-
- The parameters are:
-
- GDBM_FILE dbf
- the pointer returned by gdbm_open
-
- datum key
- the key data
-
- The ret value is -1 if the item is not present or the
- requester is a reader. The ret value is 0 if there was
- a successful delete.
-
- The next two routines allow for accessing all items in the
- database. This access is not key sequential, but it is guaran-
- teed to visit every key in the database once. (The order has to
- do with the hash values.)
-
- key = gdbm_firstkey(dbf)
-
- nextkey = gdbm_nextkey(dbf, key)
-
- The parameters are:
-
- GDBM_FILE dbf
- the pointer returned by gdbm_open
- datum key
- the key data
-
- The return values are both datum. If key.dptr or
- nextkey.dptr is NULL, there is no first key or next
- key. Again notice that dptr points to data allocated by
- malloc and gdbm will not free it for you.
-
- The following routine should be used very seldom.
-
- ret = gdbm_reorganize(dbf);
-
- If you have had a lot of deletions and would like to shrink the
- space used by the gdbm file, the this routine will reorganize
- the database. gdbm will not shorten the length of a gdbm file
- except by using this reorganization. (Deleted file space will
- be reused.)
-
- The following two are variables that may need to be used:
-
- gdbm_error gdbm_errno
- the variable that contains more information about gdbm
- errors. (gdbm.h has the definitions of the error
- values.)
-
- char *gdbm_version
- the string containing the version information.
-
- There are a few more things of interest. First, gdbm files are
- not "sparse". You can copy them with the UNIX cp command and
- they will not expand in the copying process. Also, there is a
- compatibility mode for use with programs that already use UNIX
- dbm. In this compatibility mode, no gdbm file pointer is re-
- quired by the user. Only one file may be opened at a time. All
- users in compatibility mode are assumed to be writers. If the
- gdbm file is a read only, it will fail as a writer, but will
- also try to open it as a reader. All returned pointers in datum
- structures point to data that gdbm WILL free. They should be
- treated as static pointers (as standard UNIX dbm does).
-
- SEE ALSO
- dbm(3x), ndbm(3),conv2gdbm(1)
-
- NOTES
- If you port gdbm to another system, try to follow the change
- style used for System V changes. Please send your changes to
- phil@cs.wwu.edu if you would like your changes included in a
- future release of gdbm.
-
- Please send bug reports to bug-gnu-utils@prep.ai.mit.edu.
-
- COMPATIBILITY
- NOTE: Some implementations have an include file "dbm.h". That
- file is just a file that defines datum and the above routines.
- Many original dbm sites do not have a "dbm.h" file. One is
- included here for those who want it.
-
- WARNING: standard UNIX dbm and GNU dbm do not have the same data
- format in the file. You cannot access a standard UNIX dbm file
- with GNU dbm! If you want to use an old database with GNU dbm,
- you must use the convert program.
-
- Also, GNU dbm has compatibility routines for ndbm. For ndbm
- compatiblity routines, you need the include file "ndbm.h".
-
- WARNING: If you have ndbm and gdbm, there is a conflict in the
- names of the include file for the ndbm interface and the
- original ndbm package. Do not blindly copy "ndbm.h" to your
- include directory.
-
- For compatibility with the standard dbm, the following routines
- are defined. There is an include file for dbm users called
- ``dbm.h''.
-
- int dbminit(name)
-
- int store(key, content)
-
- datum fetch(key)
-
- int delete(key)
-
- datum firstkey()
-
- datum nextkey(key)
-
- There are also compatibility routines for ndbm. For ndbm com-
- patiblity routines, you need the include file ``ndbm.h''. The
- routines are:
-
- DBM *dbm_open(name, flags, mode)
-
- void dbm_close(file)
-
- datum dbm_fetch(file, key)
-
- int dbm_store(file, key, content, flags)
-
- int dbm_delete(file, key)
-
- datum dbm_firstkey(file)
-
- datum dbm_nextkey(file)
-
- int dbm_error(file)
-
- int dbm_clearerr(file)
-
- int dbm_pagfno(file)
-
- int dbm_dirfno(file)
-
- Again, just like ndbm, any returned datum can be assumed to be
- static storage. You do not have to free that memory, the ndbm
- compatibility routines will do it for you.
-
-